//
//  CatShareListCell.m
//  EquesCat
//
//  Created by Chun Hung Cheung on 2024/12/20.
//

#import "CatShareListCell.h"

@implementation CatShareListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setup];
    }
    return self;
    
}

- (void)setup
{

      _iconImageview = [[UIImageView alloc]init];
      _iconImageview.layer.cornerRadius = 20;
     _iconImageview.layer.masksToBounds = YES;
     [self.contentView addSubview:_iconImageview];
     [_iconImageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(15);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(40);
      }];
    
    
     _checkImageview = [[UIImageView alloc]init];
     _checkImageview.image = [UIImage imageNamed:@"share_arrow.png"];
    [self.contentView addSubview:_checkImageview];
    [_checkImageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-15);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.width.mas_equalTo(6);
        make.height.mas_equalTo(10);
    }];
    
     _lineview = [[UIView alloc]init];
     _lineview.backgroundColor = [HexChangeRGB colorWithHexString:@"#e0e0e0"];
    [self.contentView addSubview:_lineview];
    [_lineview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconImageview.mas_left);
        make.right.equalTo(_checkImageview.mas_right);
        make.height.mas_equalTo(1);
        make.bottom.equalTo(self.contentView.mas_bottom);
    }];
    
     _NickNameLabel = [[UILabel alloc]init];
     _NickNameLabel.textAlignment = NSTextAlignmentLeft;
     _NickNameLabel.textColor = [HexChangeRGB colorWithHexString:@"#666666"];
     _NickNameLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:16];
    [self.contentView addSubview:_NickNameLabel];
    [_NickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconImageview.mas_right).offset(10);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(20);
        make.right.equalTo(_checkImageview.mas_left);
    }];
}


+ (CGFloat)cellHight
{
    return 60;
}

- (void)setDict:(NSDictionary *)dict
{
    /*
     {
         bid = c37d9c74c4b040ffa781df7f32e55fa9;
         name = wxh123;
         nick = "\U7231\U4f60\U4e00\U4e07\U5e74";
         "user_avatar" = AHKOAQABFwAvYXZhdGFyLzZReTVRSlZPR1k4LnBuZwA;
     }
     */
     _dict = dict;
    if ([dict objectForKey:@"nick"]) {
      _NickNameLabel.text = [dict objectForKey:@"nick"];
    }else{
      _NickNameLabel.text = [dict objectForKey:@"name"];
    }
    if ([dict objectForKey:@"user_avatar"] && [NSString stringWithFormat:@"%@",[dict objectForKey:@"user_avatar"]].length > 0) {
     
        NSString *Firststr =  [[dict objectForKey:@"user_avatar"] substringToIndex:1];
        if ([Firststr isEqualToString:@"A"] || [Firststr isEqualToString:@"B"]) {
    
                [_iconImageview sd_setImageWithURL:[YKBusinessFramework equesDownloadSharingVideo:[dict objectForKey:@"user_avatar"]] placeholderImage:[UIImage imageNamed:@"ic_menu_eques_logo.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                }];
        }else{
                [_iconImageview sd_setImageWithURL:[NSURL URLWithString:[dict objectForKey:@"user_avatar"]] placeholderImage:[UIImage imageNamed:@"ic_menu_eques_logo.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                }];
        }
    }else{
    
       _iconImageview.image =[UIImage imageNamed:@"ic_menu_eques_logo.png"];
    }
 
}


@end
